from rest_framework.generics import ListAPIView
from rest_framework.viewsets import ModelViewSet

from meiduo_admin.option.option_serializers import OptionSerializer, SpecSimpleSerializer
from meiduo_admin.user.my_pagination import MyNumberPagination
from goods.models import SpecificationOption, SPUSpecification


class OptionViewSet(ModelViewSet):
    pagination_class = MyNumberPagination
    queryset = SpecificationOption.objects.all()
    serializer_class = OptionSerializer


class OptionSimpleView(ListAPIView):
    pagination_class = None
    serializer_class = SpecSimpleSerializer

    # queryset = SPUSpecification.objects.all()
    def get_queryset(self):
        queryset = SPUSpecification.objects.all()
        for spec in queryset:
            # spec.name = spec.spu.name + " - " + spec.name
            spec.name = f"{spec.spu.name} - {spec.name}"
        return queryset
